import request from '@/utils/request'
import qs from 'qs'

// 获取验证码
export function getYzmCode() {
    return request.get(
        { url: '/code' },
        { withToken: false }
    )
}

// 账号密码登录
export function accountLogin(data: Record<string, any>) {
    return request.post(
        { url: '/auth/login', data },
        { withToken: false }
    )
}

// 微信小程序登录
export function mnpLogin(code: string) {
    const form = {
        mobile: `APP-MINI@${code}`,
        code: code,
        grant_type: 'mobile',
        scope: 'server'
    }
    return request.post(
        {
            url: '/auth/perm/oauth2/token?' + qs.stringify(form),
            header: {
                Authorization: 'Basic bWluaTptaW5p', //"mini:mini"
                'content-type': 'application/x-www-form-urlencoded'
            }
        },
        { withToken: false }
    )
}

//注册
export function register(data: Record<string, any>) {
    return request.post({ url: '/app/appuser/register', data })
}

//忘记密码
export function forgotPassword(data: Record<string, any>) {
    return request.post({ url: '/app/login/forgotPassword', data })
}

//向微信请求code的链接
export function getWxCodeUrl() {
    return request.get({
        url: '/auth/app/login/oaCodeUrl',
        data: { url: location.href }
    })
}

// 公众号登录
export function OALogin() {
    return
}
